package com.onlinevideo.dao.impl;

import com.onlinevideo.dao.BaseDao;
import com.onlinevideo.dao.CategoryDao;
import com.onlinevideo.entity.Category;

import java.util.List;

public class CategoryDaoImpl extends BaseDao implements CategoryDao {

    @Override
    public int insert(Category category) {
        String sql ="INSERT INTO `T_category` (`category_name`) VALUES (?)";
        return super.update(sql,category.getCategoryName());
    }

    @Override
    public int delete(Long id) {
        String sql = "DELETE FROM `T_category` WHERE `id`=?";
        return super.update(sql,id);
    }

    @Override
    public int update(Category category) {
        String sql = "UPDATE `T_category` SET `category_name`=? WHERE `id`=?";
        return super.update(sql,category.getCategoryName(),category.getId());
    }

    @Override
    public Category queryById(Long id) {
        String sql ="SELECT `id`,`category_name` AS `categoryName` FROM `T_category` WHERE 1=1 AND `id`=?  ";
        return super.queryForOne(Category.class,sql,id);
    }

    @Override
    public Category queryByCategory(String categoryName) {
        String sql ="SELECT `id`,`category_name` AS `categoryName` FROM `T_category` WHERE 1=1 AND `category_name`=?  ";
        return super.queryForOne(Category.class,sql,categoryName);
    }

    @Override
    public List<Category> queryAll() {
        String sql ="SELECT `id`,`category_name` AS `categoryName` FROM `T_category` WHERE 1=1  ";
        return super.queryForList(Category.class,sql);
    }
}
